
package br.ufscar.sor.ppgccs.educatransito.entidade;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Joaquim
 */
@Entity
@Table(name = "forum")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Forum.findAll", query = "SELECT f FROM Forum f"),
    @NamedQuery(name = "Forum.findByIdforum", query = "SELECT f FROM Forum f WHERE f.idforum = :idforum"),
    @NamedQuery(name = "Forum.findByAssunto", query = "SELECT f FROM Forum f WHERE f.assunto = :assunto"),
    @NamedQuery(name = "Forum.findByDtInsercao", query = "SELECT f FROM Forum f WHERE f.dtInsercao = :dtInsercao")})
public class Forum implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idforum")
    private Integer idforum;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "assunto")
    private String assunto;
    @Lob
    @Size(max = 65535)
    @Column(name = "topico")
    private String topico;
    @Column(name = "dtInsercao")
    @Temporal(TemporalType.DATE)
    private Date dtInsercao;
    @JoinColumn(name = "idUsuario", referencedColumnName = "idUsuario")
    @ManyToOne(optional = false)
    private Usuario idUsuario;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idforum")
    private List<Comentarios> comentariosList;

    public Forum() {
    }

    public Forum(Integer idforum) {
        this.idforum = idforum;
    }

    public Forum(Integer idforum, String assunto) {
        this.idforum = idforum;
        this.assunto = assunto;
    }

    public Integer getIdforum() {
        return idforum;
    }

    public void setIdforum(Integer idforum) {
        this.idforum = idforum;
    }

    public String getAssunto() {
        return assunto;
    }

    public void setAssunto(String assunto) {
        this.assunto = assunto;
    }

    public String getTopico() {
        return topico;
    }

    public void setTopico(String topico) {
        this.topico = topico;
    }

    public Date getDtInsercao() {
        return dtInsercao;
    }

    public void setDtInsercao(Date dtInsercao) {
        this.dtInsercao = dtInsercao;
    }

    public Usuario getIdUsuario() {
        return idUsuario;
    }

    public void setIdUsuario(Usuario idUsuario) {
        this.idUsuario = idUsuario;
    }

    @XmlTransient
    public List<Comentarios> getComentariosList() {
        return comentariosList;
    }

    public void setComentariosList(List<Comentarios> comentariosList) {
        this.comentariosList = comentariosList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idforum != null ? idforum.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Forum)) {
            return false;
        }
        Forum other = (Forum) object;
        if ((this.idforum == null && other.idforum != null) || (this.idforum != null && !this.idforum.equals(other.idforum))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return this.assunto;
    }
    
}
